<?php

/*
 * Snippet 1 from
 * http://www.php.net/manual/en/language.types.string.php
 */


/*
 * Create an instance of IndentedTextWriter to hold the generated code
 */

$writer = new IndentedTextWriter();

/*
 * Create an instance of the code generator options class
 */

$options = new CodeGeneratorOptions();

/*
 * Set the bracing style:
 */

$options->set_BracingStyle(BracingStyle::KR);

/*
 * both $writer and $options will be arguments to one of
 * the PHPCodeProvider code generating methods.
 * Create an instance of the PHP code provider class
 */

$provider = new PHPCodeProvider();

/*
 * Start creating the code tree.
 */

$defaultNamespace = new CodeNamespace();

/*
 * Start adding statements to the namespace.
 */

$s1 = <<<'EOT'
this is a simple string
EOT;

$echo1 = new EchoStatement();
$echo1->OutputParameters->add(
    new DoubleQUotedStringExpression($s1));
$echo1->BlankLinesAfter = 1;

$s2 = <<<'EOT'
You deleted C:\\*.*?
EOT;
$echo2 = new EchoStatement();
$echo2->OutputParameters->add(
    new DoubleQUotedStringExpression($s2));
$echo2->BlankLinesAfter = 1;

$s3 = <<<'EOT'
Arnold once said: \"I'll be back\"
EOT;

$echo3 = new EchoStatement();
$echo3->OutputParameters->add(
    new DoubleQUotedStringExpression($s3));
$echo3->BlankLinesAfter = 1;

$s4 = <<<'EOT'
You deleted C:\*.*?
EOT;

$echo4 = new EchoStatement();
$echo4->OutputParameters->add(
    new DoubleQUotedStringExpression($s4));
$echo4->BlankLinesAfter = 1;

$s5 = <<<'EOT'
This will expand: \n a newline
EOT;

$echo5 = new EchoStatement();
$echo5->OutputParameters->add(
    new DoubleQUotedStringExpression($s5));
$echo5->BlankLinesAfter = 1;

$s6 = <<<'EOT'
Variables do $expand
EOT;

$echo6 = new EchoStatement();
$echo6->OutputParameters->add(
    new DoubleQUotedStringExpression($s6));
$echo6->BlankLinesAfter = 1;

/*
 * Add the statements to the default namespace
 */

$defaultNamespace->Statements->add($echo1);
$defaultNamespace->Statements->add($echo2);
$defaultNamespace->Statements->add($echo3);
$defaultNamespace->Statements->add($echo4);
$defaultNamespace->Statements->add($echo5);
$defaultNamespace->Statements->add($echo6);

/*
 * Generate the code
 */

$provider->generateCodeFromNamespace($defaultNamespace, $writer, $options);

/*
 * Print the generated code
 */

echo 
    '<pre>' . str_replace(
        '<br />', '', highlight_string($writer->get_String(), true)) . 
    '<pre/>';

/*
 * The output should be:
 * (no support for octal or hexadecimal integers)
 * 
 * 
 */


?>
